# Replication code for Taylor C. Boas, Dino P. Christenson, and David M. Glick, "Recruiting Large Online Samples in the United States and India: Facebook, Mechanical Turk and Qualtrics," Political Science Research and Methods.

# Analysis conducted in R 3.4.3 on MacOS 10.13.2

# NOTE: This file produces figures and tables related to subject cooperativeness: Main Text Figure 8 and Appendix Table 7. Files should be run in the following order; please see readme.txt for details.
# 	1. clean_us_survey.R
# 	2. clean_india_survey.R
# 	3. merge_external_data_us.R
# 	4. merge_external_data_india.R
# 	5. analyze_demographics.R
# 	6. analyze_spaces.R
# 	7. analyze_politics.R
# 	8. analyze_cooperativeness.R
# 	9. analyze_experiments.R

# Set working directory as appropriate
# setwd('~/Dropbox/sample recruitment shared/replication/')

# Clean desktop and load packages. Please make sure all necessary packages are installed.
rm(list=ls(all=T))
library(Hmisc)
library(foreign)
library(survey)

# Load survey data. Includes original, cleaned survey data files (india.RData and us.RData), prior to the elimination of incomplete surveys.

load('india_completions_augmented.RData')
load('us_completions_augmented.RData')
load('india.RData')
load('us.RData')
load('gss.RData')
load('wvs.RData')

# US sample for unweighted analysis: excluding targeted respondents in Facebook/MTurk samples

us1$nontarg<-((us1$sample=='Qualtrics')|(us1$sample=='Facebook'&us1$targ==0)|(us1$sample=='MTurk'&us1$StartDate <= as.POSIXct('2015-12-31 23:59:59 EST')))
us$nontarg<-((us$sample=='Qualtrics')|(us$sample=='Facebook'&us$targ==0)|(us$sample=='MTurk'&us$StartDate <= as.POSIXct('2015-12-31 23:59:59 EST')))

###########################################
# Appendix Table 7: Subject Cooperativeness
###########################################

# New variables and weighted design objects

us1$income<-ifelse(us1$Q31==13, NA, us1$Q31)
india1$income<-ifelse(india1$Q28==9, NA, india1$Q28)

us1.design<-svydesign(ids=~1,weights= us1$weight,data=us1)
india1.design<-svydesign(ids=~1,weights= india1$weight,data= india1)

us2.design<-svydesign(ids=~1,weights= us1$weight[us1$Q31_dk==1],data=us1[us1$Q31_dk==1,])
india2.design<-svydesign(ids=~1,weights= india1$weight[india1$Q28_dk==1],data=india1[india1$Q28_dk==1,])

# Screener

reg.screener.us<-with(us1[us1$nontarg,],lm(I(Q11==12)~sample))
reg.screener.us.wtd<-svyglm(I(Q11==12)~sample, design= us1.design)

reg.screener.india<-with(india1,lm(I(Q11==13)~sample))
reg.screener.india.wtd<-svyglm(I(Q11==13)~sample, design= india1.design)

# DK on income

reg.income_dk.us<-with(us1[us1$nontarg & us1$Q31_dk==1,],lm(I(Q31==13)~sample))
reg.income_dk.us.wtd<-svyglm(I(Q31==13)~sample, design= us2.design)

reg.income_dk.india<-with(india1[india1$Q28_dk==1,],lm(I(Q28==9)~sample))
reg.income_dk.india.wtd<-svyglm(I(Q28==9)~sample, design= india2.design)

wvs.income_dk.india<-mean(is.na(wvs$V239))
gss.income_dk.us<-mean(is.na(gss$income06))

# Survey drop-out

reg.dropout.us<-with(us[us$nontarg,],lm(I(pct_progress<100)~sample))
reg.dropout.india<-with(india,lm(I(pct_progress<100)~sample))

# Reported contact and non-naivite

reg.contact.us<-with(us1[us1$nontarg,],lm(I(Q32==1)~sample))
reg.contact.us.wtd<-svyglm(I(Q32==1)~sample, design= us1.design)

reg.contact.india<-with(india1,lm(I(Q29==1)~sample))
reg.contact.india.wtd<-svyglm(I(Q29==1)~sample, design= india1.design)

reg.frequent.us<-with(us1[us1$nontarg,],lm(I(-1*Q33+6)~sample))
reg.frequent.us.wtd<-svyglm(I(-1*Q33+6)~sample, design= us1.design)

reg.frequent.india<-with(india1,lm(I(-1*Q30+6)~sample))
reg.frequent.india.wtd<-svyglm(I(-1*Q30+6)~sample, design= india1.design)

# Gather coefficients, make combo table

benchmark<-round(c(.57, NA, gss.income_dk.us, wvs.income_dk.india, rep(NA,6)),2)
est.fb<-round(sapply(list(reg.screener.us, reg.screener.india, reg.income_dk.us, reg.income_dk.india, reg.dropout.us, reg.dropout.india, reg.contact.us, reg.contact.india, reg.frequent.us, reg.frequent.india), function(x) coef(x)[1]),2)
est.fb.wtd<-round(sapply(list(reg.screener.us.wtd, reg.screener.india.wtd, reg.income_dk.us.wtd, reg.income_dk.india.wtd, reg.contact.us.wtd, reg.contact.india.wtd, reg.frequent.us.wtd, reg.frequent.india.wtd), function(x) coef(x)[1]),2)
est.fb.wtd<-c(est.fb.wtd[1:4],NA,NA, est.fb.wtd[5:8])
est.mt<-round(sapply(list(reg.screener.us, reg.screener.india, reg.income_dk.us, reg.income_dk.india, reg.dropout.us, reg.dropout.india, reg.contact.us, reg.contact.india, reg.frequent.us, reg.frequent.india), function(x) sum(coef(x)[1:2])),2)
est.mt.wtd<-round(sapply(list(reg.screener.us.wtd, reg.screener.india.wtd, reg.income_dk.us.wtd, reg.income_dk.india.wtd, reg.contact.us.wtd, reg.contact.india.wtd, reg.frequent.us.wtd, reg.frequent.india.wtd), function(x) sum(coef(x)[1:2])),2)
est.mt.wtd<-c(est.mt.wtd[1:4],NA,NA, est.mt.wtd[5:8])
est.qt<-round(sapply(list(reg.screener.us, reg.screener.india, reg.income_dk.us, reg.income_dk.india, reg.dropout.us, reg.dropout.india, reg.contact.us, reg.contact.india, reg.frequent.us, reg.frequent.india), function(x) sum(coef(x)[c(1,3)])),2)
est.qt.wtd<-round(sapply(list(reg.screener.us.wtd, reg.screener.india.wtd, reg.income_dk.us.wtd, reg.income_dk.india.wtd, reg.contact.us.wtd, reg.contact.india.wtd, reg.frequent.us.wtd, reg.frequent.india.wtd), function(x) sum(coef(x)[c(1,3)])),2)
est.qt.wtd<-c(est.qt.wtd[1:4],NA,NA, est.qt.wtd[5:8])

coop.table<-cbind(benchmark,est.fb,est.fb.wtd,est.mt,est.mt.wtd,est.qt,est.qt.wtd)
rownames(coop.table)<-rep(c('United States','India'),5)
colnames(coop.table)<-c('Benchmark','Facebook','Facebook\nWeighted','MTurk','MTurk\nWeighted','Qualtrics','Qualtrics\nWeighted')

coop.table.note<-"NOTE: Benchmarks are Study 2 in \\citet{berinsky2014separating} (U.S. screener passage), the 2014 General Social Survey cross-section (U.S. ``don't know'' income), and the 2014 World Values Survey (India ``don't know'' income). Weights are post-stratification, based on region (four categories in the U.S., five in India), age (quartiles in the U.S., above/below median in India), and sex in each country's most recent census."

coop.table.latex<-latex(coop.table,file='coop_table.tex', rowlabel = '', collabel.just=rep('c',ncol(coop.table)), col.just=rep('c',ncol(coop.table)), rgroup=c('Screener Passage',"``Don't Know'' Income",'Survey Drop-out', 'Discuss with Others','Frequent Surveys (1--5)'), n.rgroup=rep(2,5), caption = 'Subject Cooperativeness in India and the United States', extracolsize='normalsize', insert.bottom= coop.table.note, booktabs = F, ctable = T, where = "htp")

#############################################
# Main Text Figure 8: Subject Cooperativeness
#############################################

# Weighted design objects, convenience samples only

us.fb.design<-svydesign(ids=~1,weights= us1$weight[us1$sample=='Facebook'],data= us1[us1$sample=='Facebook',])
us.mt.design<-svydesign(ids=~1,weights= us1$weight[us1$sample=='MTurk'],data= us1[us1$sample=='MTurk',])
us.qt.design<-svydesign(ids=~1,weights= us1$weight[us1$sample=='Qualtrics'],data= us1[us1$sample=='Qualtrics',])
us.dk_income.fb.design<-svydesign(ids=~1,weights= us1$weight[us1$Q31_dk==1 & us1$sample=='Facebook'],data= us1[us1$Q31_dk==1 & us1$sample=='Facebook',])
us.dk_income.mt.design<-svydesign(ids=~1,weights= us1$weight[us1$Q31_dk==1 & us1$sample=='MTurk'],data= us1[us1$Q31_dk==1 & us1$sample=='MTurk',])
us.dk_income.qt.design<-svydesign(ids=~1,weights= us1$weight[us1$Q31_dk==1 & us1$sample=='Qualtrics'],data= us1[us1$Q31_dk==1 & us1$sample=='Qualtrics',])

india.fb.design<-svydesign(ids=~1,weights= india1$weight[india1$sample=='Facebook'],data= india1[india1$sample=='Facebook',])
india.mt.design<-svydesign(ids=~1,weights= india1$weight[india1$sample=='MTurk'],data= india1[india1$sample=='MTurk',])
india.qt.design<-svydesign(ids=~1,weights= india1$weight[india1$sample=='Qualtrics'],data= india1[india1$sample=='Qualtrics',])
india.dk_income.fb.design<-svydesign(ids=~1,weights= india1$weight[india1$Q28_dk==1 & india1$sample=='Facebook'],data= india1[india1$Q28_dk==1 & india1$sample=='Facebook',])
india.dk_income.mt.design<-svydesign(ids=~1,weights= india1$weight[india1$Q28_dk==1 & india1$sample=='MTurk'],data= india1[india1$Q28_dk==1 & india1$sample=='MTurk',])
india.dk_income.qt.design<-svydesign(ids=~1,weights= india1$weight[india1$Q28_dk==1 & india1$sample=='Qualtrics'],data= india1[india1$Q28_dk==1 & india1$sample=='Qualtrics',])

# Screener
mean.us.screener.fb<-with(us1[us1$nontarg & us1$sample=='Facebook',],lm(I(Q11==12)~1))
mean.us.screener.mt<-with(us1[us1$nontarg & us1$sample=='MTurk',],lm(I(Q11==12)~1))
mean.us.screener.qt<-with(us1[us1$nontarg & us1$sample=='Qualtrics',],lm(I(Q11==12)~1))

mean.us.screener.fb.wtd<-svyglm(I(Q11==12)~1, design= us.fb.design)
mean.us.screener.mt.wtd<-svyglm(I(Q11==12)~1, design= us.mt.design)
mean.us.screener.qt.wtd<-svyglm(I(Q11==12)~1, design= us.qt.design)

mean.india.screener.fb<-with(india1[india1$sample=='Facebook',],lm(I(Q11==13)~1))
mean.india.screener.mt<-with(india1[india1$sample=='MTurk',],lm(I(Q11==13)~1))
mean.india.screener.qt<-with(india1[india1$sample=='Qualtrics',],lm(I(Q11==13)~1))

mean.india.screener.fb.wtd<-svyglm(I(Q11==13)~1, design= india.fb.design)
mean.india.screener.mt.wtd<-svyglm(I(Q11==13)~1, design= india.mt.design)
mean.india.screener.qt.wtd<-svyglm(I(Q11==13)~1, design= india.qt.design)

# DK on income

mean.us.dk_income.fb<-with(us1[us1$nontarg & us1$Q31_dk==1 & us1$sample=='Facebook',],lm(I(Q31==13)~1))
mean.us.dk_income.mt<-with(us1[us1$nontarg & us1$Q31_dk==1 & us1$sample=='MTurk',],lm(I(Q31==13)~1))
mean.us.dk_income.qt<-with(us1[us1$nontarg & us1$Q31_dk==1 & us1$sample=='Qualtrics',],lm(I(Q31==13)~1))

mean.us.dk_income.fb.wtd<-svyglm(I(Q31==13)~1, design= us.dk_income.fb.design)
mean.us.dk_income.mt.wtd<-svyglm(I(Q31==13)~1, design= us.dk_income.mt.design)
mean.us.dk_income.qt.wtd<-svyglm(I(Q31==13)~1, design= us.dk_income.qt.design)

mean.india.dk_income.fb<-with(india1[india1$Q28_dk==1 & india1$sample=='Facebook',],lm(I(Q28==9)~1))
mean.india.dk_income.mt<-with(india1[india1$Q28_dk==1 & india1$sample=='MTurk',],lm(I(Q28==9)~1))
mean.india.dk_income.qt<-with(india1[india1$Q28_dk==1 & india1$sample=='Qualtrics',],lm(I(Q28==9)~1))

mean.india.dk_income.fb.wtd<-svyglm(I(Q28==9)~1, design= india.dk_income.fb.design)
mean.india.dk_income.mt.wtd<-svyglm(I(Q28==9)~1, design= india.dk_income.mt.design)
mean.india.dk_income.qt.wtd<-svyglm(I(Q28==9)~1, design= india.dk_income.qt.design)

# For representative samples recoding NA's as 'na' to use regression to get mean and SE

wvs$inc<-as.character(wvs$V239)
wvs$inc[is.na(wvs$inc)]<-'na'
gss$inc<-as.character(gss$income06)
gss$inc[is.na(gss$inc)]<-'na'

mean.us.dk_income.gss<-lm(I(gss$inc=='na')~1)
mean.india.dk_income.wvs<-lm(I(wvs$inc=='na')~1)

# Survey drop-out

mean.us.dropout.fb<-with(us[us$nontarg & us$sample=='Facebook',],lm(I(pct_progress<100)~1))
mean.us.dropout.mt<-with(us[us$nontarg & us$sample=='MTurk',],lm(I(pct_progress<100)~1))
mean.us.dropout.qt<-with(us[us$nontarg & us$sample=='Qualtrics',],lm(I(pct_progress<100)~1))

mean.india.dropout.fb<-with(india[india$sample=='Facebook',],lm(I(pct_progress<100)~1))
mean.india.dropout.mt<-with(india[india$sample=='MTurk',],lm(I(pct_progress<100)~1))
mean.india.dropout.qt<-with(india[india$sample=='Qualtrics',],lm(I(pct_progress<100)~1))

# Reported contact

mean.us.contact.fb<-with(us1[us1$nontarg & us1$sample=='Facebook',],lm(I(Q32==1)~1))
mean.us.contact.mt<-with(us1[us1$nontarg & us1$sample=='MTurk',],lm(I(Q32==1)~1))
mean.us.contact.qt<-with(us1[us1$nontarg & us1$sample=='Qualtrics',],lm(I(Q32==1)~1))

mean.us.contact.fb.wtd<-svyglm(I(Q32==1)~1, design= us.fb.design)
mean.us.contact.mt.wtd<-svyglm(I(Q32==1)~1, design= us.mt.design)
mean.us.contact.qt.wtd<-svyglm(I(Q32==1)~1, design= us.qt.design)

mean.india.contact.fb<-with(india1[india1$sample=='Facebook',],lm(I(Q29==1)~1))
mean.india.contact.mt<-with(india1[india1$sample=='MTurk',],lm(I(Q29==1)~1))
mean.india.contact.qt<-with(india1[india1$sample=='Qualtrics',],lm(I(Q29==1)~1))

mean.india.contact.fb.wtd<-svyglm(I(Q29==1)~1, design= india.fb.design)
mean.india.contact.mt.wtd<-svyglm(I(Q29==1)~1, design= india.mt.design)
mean.india.contact.qt.wtd<-svyglm(I(Q29==1)~1, design= india.qt.design)

# Reported non-naivite

mean.us.frequent.fb<-with(us1[us1$nontarg & us1$sample=='Facebook',],lm(I(-.25*Q33+1.25)~1))
mean.us.frequent.mt<-with(us1[us1$nontarg & us1$sample=='MTurk',],lm(I(-.25*Q33+1.25)~1))
mean.us.frequent.qt<-with(us1[us1$nontarg & us1$sample=='Qualtrics',],lm(I(-.25*Q33+1.25)~1))

mean.us.frequent.fb.wtd<-svyglm(I(-.25*Q33+1.25)~1, design= us.fb.design)
mean.us.frequent.mt.wtd<-svyglm(I(-.25*Q33+1.25)~1, design= us.mt.design)
mean.us.frequent.qt.wtd<-svyglm(I(-.25*Q33+1.25)~1, design= us.qt.design)

mean.india.frequent.fb<-with(india1[india1$sample=='Facebook',],lm(I(-.25*Q30+1.25)~1))
mean.india.frequent.mt<-with(india1[india1$sample=='MTurk',],lm(I(-.25*Q30+1.25)~1))
mean.india.frequent.qt<-with(india1[india1$sample=='Qualtrics',],lm(I(-.25*Q30+1.25)~1))

mean.india.frequent.fb.wtd<-svyglm(I(-.25*Q30+1.25)~1, design= india.fb.design)
mean.india.frequent.mt.wtd<-svyglm(I(-.25*Q30+1.25)~1, design= india.mt.design)
mean.india.frequent.qt.wtd<-svyglm(I(-.25*Q30+1.25)~1, design= india.qt.design)

# Gather coefficients, make dot-plot

mean.benchmark<-c(.57, NA, coef(mean.us.dk_income.gss), coef(mean.india.dk_income.wvs), rep(NA,6))
mean.fb<-sapply(list(mean.us.screener.fb, mean.india.screener.fb, mean.us.dk_income.fb, mean.india.dk_income.fb, mean.us.dropout.fb, mean.india.dropout.fb, mean.us.contact.fb, mean.india.contact.fb, mean.us.frequent.fb, mean.india.frequent.fb),coef)
mean.fb.wtd<-sapply(list(mean.us.screener.fb.wtd, mean.india.screener.fb.wtd, mean.us.dk_income.fb.wtd, mean.india.dk_income.fb.wtd, mean.us.contact.fb.wtd, mean.india.contact.fb.wtd, mean.us.frequent.fb.wtd, mean.india.frequent.fb.wtd),coef)
mean.fb.wtd<-c(mean.fb.wtd[1:4],NA,NA, mean.fb.wtd[5:8])
mean.mt<-sapply(list(mean.us.screener.mt, mean.india.screener.mt, mean.us.dk_income.mt, mean.india.dk_income.mt, mean.us.dropout.mt, mean.india.dropout.mt, mean.us.contact.mt, mean.india.contact.mt, mean.us.frequent.mt, mean.india.frequent.mt),coef)
mean.mt.wtd<-sapply(list(mean.us.screener.mt.wtd, mean.india.screener.mt.wtd, mean.us.dk_income.mt.wtd, mean.india.dk_income.mt.wtd, mean.us.contact.mt.wtd, mean.india.contact.mt.wtd, mean.us.frequent.mt.wtd, mean.india.frequent.mt.wtd),coef)
mean.mt.wtd<-c(mean.mt.wtd[1:4],NA,NA, mean.mt.wtd[5:8])
mean.qt<-sapply(list(mean.us.screener.qt, mean.india.screener.qt, mean.us.dk_income.qt, mean.india.dk_income.qt, mean.us.dropout.qt, mean.india.dropout.qt, mean.us.contact.qt, mean.india.contact.qt, mean.us.frequent.qt, mean.india.frequent.qt),coef)
mean.qt.wtd<-sapply(list(mean.us.screener.qt.wtd, mean.india.screener.qt.wtd, mean.us.dk_income.qt.wtd, mean.india.dk_income.qt.wtd, mean.us.contact.qt.wtd, mean.india.contact.qt.wtd, mean.us.frequent.qt.wtd, mean.india.frequent.qt.wtd),coef)
mean.qt.wtd<-c(mean.qt.wtd[1:4],NA,NA, mean.qt.wtd[5:8])

se.benchmark<-c(.50/sqrt(1255), NA, coef(summary(mean.us.dk_income.gss))[2], coef(summary(mean.india.dk_income.wvs))[2], rep(NA,6))
se.fb<-sapply(list(mean.us.screener.fb, mean.india.screener.fb, mean.us.dk_income.fb, mean.india.dk_income.fb, mean.us.dropout.fb, mean.india.dropout.fb, mean.us.contact.fb, mean.india.contact.fb, mean.us.frequent.fb, mean.india.frequent.fb),function(x) coef(summary(x))[2])
se.fb.wtd<-sapply(list(mean.us.screener.fb.wtd, mean.india.screener.fb.wtd, mean.us.dk_income.fb.wtd, mean.india.dk_income.fb.wtd, mean.us.contact.fb.wtd, mean.india.contact.fb.wtd, mean.us.frequent.fb.wtd, mean.india.frequent.fb.wtd),function(x) coef(summary(x))[2])
se.fb.wtd<-c(se.fb.wtd[1:4],NA,NA, se.fb.wtd[5:8])
se.mt<-sapply(list(mean.us.screener.mt, mean.india.screener.mt, mean.us.dk_income.mt, mean.india.dk_income.mt, mean.us.dropout.mt, mean.india.dropout.mt, mean.us.contact.mt, mean.india.contact.mt, mean.us.frequent.mt, mean.india.frequent.mt),function(x) coef(summary(x))[2])
se.mt.wtd<-sapply(list(mean.us.screener.mt.wtd, mean.india.screener.mt.wtd, mean.us.dk_income.mt.wtd, mean.india.dk_income.mt.wtd, mean.us.contact.mt.wtd, mean.india.contact.mt.wtd, mean.us.frequent.mt.wtd, mean.india.frequent.mt.wtd),function(x) coef(summary(x))[2])
se.mt.wtd<-c(se.mt.wtd[1:4],NA,NA, se.mt.wtd[5:8])
se.qt<-sapply(list(mean.us.screener.qt, mean.india.screener.qt, mean.us.dk_income.qt, mean.india.dk_income.qt, mean.us.dropout.qt, mean.india.dropout.qt, mean.us.contact.qt, mean.india.contact.qt, mean.us.frequent.qt, mean.india.frequent.qt),function(x) coef(summary(x))[2])
se.qt.wtd<-sapply(list(mean.us.screener.qt.wtd, mean.india.screener.qt.wtd, mean.us.dk_income.qt.wtd, mean.india.dk_income.qt.wtd, mean.us.contact.qt.wtd, mean.india.contact.qt.wtd, mean.us.frequent.qt.wtd, mean.india.frequent.qt.wtd),function(x) coef(summary(x))[2])
se.qt.wtd<-c(se.qt.wtd[1:4],NA,NA, se.qt.wtd[5:8])

# Reorder: all US variables, then all India variables

mean.benchmark<-c(mean.benchmark[1:5*2-1], mean.benchmark[1:5*2])
mean.fb<-c(mean.fb[1:5*2-1], mean.fb[1:5*2])
mean.fb.wtd<-c(mean.fb.wtd[1:5*2-1], mean.fb.wtd[1:5*2])
mean.mt<-c(mean.mt[1:5*2-1], mean.mt[1:5*2])
mean.mt.wtd<-c(mean.mt.wtd[1:5*2-1], mean.mt.wtd[1:5*2])
mean.qt<-c(mean.qt[1:5*2-1], mean.qt[1:5*2])
mean.qt.wtd<-c(mean.qt.wtd[1:5*2-1], mean.qt.wtd[1:5*2])

se.benchmark<-c(se.benchmark[1:5*2-1], se.benchmark[1:5*2])
se.fb<-c(se.fb[1:5*2-1], se.fb[1:5*2])
se.fb.wtd<-c(se.fb.wtd[1:5*2-1], se.fb.wtd[1:5*2])
se.mt<-c(se.mt[1:5*2-1], se.mt[1:5*2])
se.mt.wtd<-c(se.mt.wtd[1:5*2-1], se.mt.wtd[1:5*2])
se.qt<-c(se.qt[1:5*2-1], se.qt[1:5*2])
se.qt.wtd<-c(se.qt.wtd[1:5*2-1], se.qt.wtd[1:5*2])

# Plot

lwd<-1.5
adjust<-0.15
nvars<-length(mean.benchmark)

pdf(file='coop.pdf',width=10,height=7)
par(mfrow=c(1,2))

par(mar=c(3,7,2,0)+.01)
plot(mean.benchmark, nvars:1+1.5*adjust, type='p',axes=F,frame.plot=T,xlab='',ylab='',pch=19,xlim=0:1,ylim=c(1-1.5*adjust,nvars+1.5*adjust),main='Unweighted',sub='')
Axis(side=1,at=seq(0,1,.25),labels= seq(0,1,.25))
Axis(side=2,at=c((nvars+1):0),labels=c('','Screener\nPassage',"Don't Know\nIncome",'Survey\nDrop-out', 'Discuss\nw/ Others', 'Frequent\nSurveys','Screener\nPassage',"Don't Know\nIncome",'Survey\nDrop-out', 'Discuss\nw/ Others', 'Frequent\nSurveys',''),las=1)
Axis(side=2,at=c(3,8),labels=c('India','United States'), line=4.5,tick=F,font=2)
abline(h=1:(nvars-1)+.5,lwd=1,lty=3)
abline(h= nvars/2+.5)
segments(mean.benchmark-qnorm(.975)*se.benchmark,nvars:1+1.5*adjust, mean.benchmark+qnorm(.975)*se.benchmark,nvars:1+1.5*adjust,lwd=lwd)
segments(mean.fb-qnorm(.975)*se.fb,nvars:1+0.5*adjust, mean.fb+qnorm(.975)*se.fb,nvars:1+0.5*adjust,lwd=lwd)
segments(mean.mt-qnorm(.975)*se.mt,nvars:1-0.5*adjust, mean.mt+qnorm(.975)*se.mt,nvars:1-0.5*adjust,lwd=lwd)
segments(mean.qt-qnorm(.975)*se.qt,nvars:1-1.5*adjust, mean.qt+qnorm(.975)*se.qt,nvars:1-1.5*adjust,lwd=lwd)
points(mean.fb, nvars:1+0.5*adjust, pch=21, bg='white')
points(mean.mt, nvars:1-0.5*adjust, pch=8)
points(mean.qt, nvars:1-1.5*adjust, pch=25, bg='white')

par(mar=c(3,2,2,5)+.01)
plot(mean.benchmark, nvars:1+1.5*adjust, type='p',axes=F,frame.plot=T,xlab='',ylab='',pch=19,xlim=0:1,ylim=c(1-1.5*adjust,nvars+1.5*adjust),main='Weighted',sub='')
Axis(side=1,at=seq(0,1,.25),labels= seq(0,1,.25))
abline(h=1:(nvars-1)+.5,lwd=1,lty=3)
abline(h= nvars/2+.5)
segments(mean.benchmark-qnorm(.975)*se.benchmark,nvars:1+1.5*adjust, mean.benchmark+qnorm(.975)*se.benchmark,nvars:1+1.5*adjust,lwd=lwd)
segments(mean.fb.wtd-qnorm(.975)*se.fb.wtd,nvars:1+0.5*adjust, mean.fb.wtd+qnorm(.975)*se.fb.wtd,nvars:1+0.5*adjust,lwd=lwd)
segments(mean.mt.wtd-qnorm(.975)*se.mt.wtd,nvars:1-0.5*adjust, mean.mt.wtd+qnorm(.975)*se.mt.wtd,nvars:1-0.5*adjust,lwd=lwd)
segments(mean.qt.wtd-qnorm(.975)*se.qt.wtd,nvars:1-1.5*adjust, mean.qt.wtd+qnorm(.975)*se.qt.wtd,nvars:1-1.5*adjust,lwd=lwd)
points(mean.fb.wtd, nvars:1+0.5*adjust, pch=21, bg='white')
points(mean.mt.wtd, nvars:1-0.5*adjust, pch=8)
points(mean.qt.wtd, nvars:1-1.5*adjust, pch=25, bg='white')
legend('bottomright',pch=c(19,21,8,25),legend=c('Benchmark','Facebook','MTurk','Qualtrics'),title='Sample',bg='white')
dev.off()
